using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace SMS.Framework
{
    public delegate bool OnApplicationCommandEventHandler(object sender, string commandName, object[] commandParameters);
    public class Context
    {
        private static Context _Context;
        public static Context Current
        {
            get
            {
                if (_Context == null) _Context = new Context();
                return _Context;
            }
        }

        private List<IMdiChildWindow> _MdiChildWindows;
        public List<IMdiChildWindow> MdiChildWindows
        {
            get
            {
                return _MdiChildWindows;
            }
        }

        private User _User = new User();
        public User User
        {
            get { return _User; }
            set { _User = value; }
        }

        private Store _Store = new Store();
        public Store Store
        {
            get { return _Store; }
            set { _Store = value; }
        }

        private AppInfo _AppInfo = new AppInfo();
        public AppInfo AppInfo
        {
            get { return _AppInfo; }
            set { _AppInfo = value; }
        }


        private MaterialInfo materialInfo=new MaterialInfo();

        public MaterialInfo MaterialInfo
        {
            get { return materialInfo; }
            set { materialInfo = value; }
        }

        private IMdiWindow _MdiWindow;
        public IMdiWindow MdiWindow
        {
            get { return _MdiWindow; }
            set { _MdiWindow = value; }
        }

        public void RegisterMdiWindow(IMdiWindow mdiWindow)
        {
            if (_MdiWindow == null) _MdiWindow = mdiWindow;
        }

        private ITrayWindow _TrayWindow;
        public ITrayWindow TrayWindow
        {
            get { return _TrayWindow; }
            set { _TrayWindow = value; }
        }

        public void RegisterTrayWindow(ITrayWindow trayWindow)
        {
            if (_TrayWindow == null) _TrayWindow = trayWindow;
        }

        public void RegisterMdiChildWindow(IMdiChildWindow mdiChildWindow)
        {
            if (_MdiChildWindows == null) _MdiChildWindows = new List<IMdiChildWindow>();
            _MdiChildWindows.Add(mdiChildWindow);
        }

        private event OnApplicationCommandEventHandler _OnApplicationCommand;
        public event OnApplicationCommandEventHandler OnApplicationCommand
        {
            add{ _OnApplicationCommand += value; }
            remove { _OnApplicationCommand -= value; }
        }

        public bool ExecuteApplicationCommand(object sender, string commandName, object[] commandParameters)
        {
            if (_OnApplicationCommand != null)
                return _OnApplicationCommand(sender, commandName, commandParameters);
            else
                return true;
        }
    }
}
